package com.amuse.amuse.mapper.club_permissions;

import com.amuse.amuse.entity.clubAnnouncements;
import com.amuse.amuse.entity.clubApplications;
import com.amuse.amuse.entity.clubMembers;
import com.amuse.amuse.entity.clubs;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClubPermissionsDao {
    //社团管理人员负责社团公告
   /* addClubAnnouncements社长添加社团公告*/
   @Insert("insert into clubAnnouncements(announcementId,clubId,content,publishDate,title) values(#{announcementId},#{clubId},#{content},#{publishDate},#{title})")
   public int addClubAnnouncements( @Param("announcementId") String announcementId,@Param("clubId") Integer clubId,@Param("content") String content,@Param("publishDate") String publishDate,@Param("title") String title);

   //社长删除社团公告
   @Delete("delete from clubAnnouncements where announcementId = #{announcementId} and clubId = #{clubId}")
   public int deleteClubAnnouncements(@Param("announcementId") String announcementId,@Param("clubId") Integer clubId);

   //社长更新社团公告
   @Update("update clubAnnouncements set title = #{title} , content = #{content} , publishDate = #{publishDate} where announcementId = #{announcementId} and clubId = #{clubId}")
   public int updateClubAnnouncements( @Param("clubId") Integer clubId,@Param("announcementId") String announcementId,@Param("title") String title,@Param("content") String content,@Param("publishDate") String publishDate);

   //社长修改社团介绍
   @Update("update clubs set description = #{description} where clubId = #{clubId}")
   public int updateClubDescription(@Param("clubId") Integer clubId,@Param("description") String description);

   //社长，学生查询社团公告
   @Select("select * from clubAnnouncements where clubId = #{clubId}")
   public List<clubAnnouncements> findClubAnnouncements(@Param("clubId") Integer clubId);

   //社长,学生查看社团资料
   public List<clubs> findClubsInfo(@Param("clubName") String clubName);

   //学生申请加入社团
   @Insert("insert into clubapplications(clubId,studentId) values(#{clubId},#{studentId})")
   public int StudentsApplyToClub(@Param("clubId")Integer clubId,@Param("studentId") Integer studentId);

   //社长查看社团学生申请
   @Select("select * from clubapplications where clubId = #{clubId} ")
   public List<clubApplications> findClubApplications(@Param("clubId") Integer clubId);

   //社长更改申请状态，0为拒绝，1为同意
   @Update("update clubapplications set status = #{status} where studentId = #{studentId} and clubId = #{clubId}")
   public int updateClubApplications(@Param("status") Integer status,@Param("studentId") Integer studentId,@Param("clubId") Integer clubId);

   //将状态为1的信息添加到clubMembers中
   @Insert("insert into clubMembers(clubId,studentId) values(#{clubId},#{studentId})")
   public int addClubMembers(@Param("clubId") Integer clubId,@Param("studentId") Integer studentId);


   //学生社长查看社团成员
   @Select("select * from clubMembers ")
   public List<clubMembers> findClubMembers();

   //查看学生申请表
   @Select("select * from clubApplications")
   public List<clubApplications> findClubApplications1();

   //查看各社团的人数
   @Select("select count(*) from clubmembers where clubId = #{clubId}")
   public Integer clubMembersCount(@Param("clubId") Integer clubId);

   //更新各个社团的社团人数
   @Update("update clubs set currentMember = #{currentMember} where clubId = #{clubId}")
   public Integer updateCurrentMember(@Param("clubId") Integer clubId,@Param("currentMember") Integer currentMember);

   //实时获取社团人数/容量
   @Select("select capacity,currentMember from clubs where clubId = #{clubId}")
   public clubs getCurrentMember(@Param("clubId") Integer clubId);


}
